<template>
  <div class="page-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>配电间列表</span>
          <el-button type="primary" @click="handleAdd">新增配电间</el-button>
        </div>
      </template>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="roomCode" label="配电间编号" width="150" />
        <el-table-column prop="roomName" label="配电间名称" />
        <el-table-column prop="building" label="所属建筑" />
        <el-table-column prop="floor" label="楼层" />
        <el-table-column prop="voltage" label="电压等级" />
        <el-table-column prop="capacity" label="容量(kVA)" />
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="responsible" label="负责人" />
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button size="small" @click="handleEdit(row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        v-model:current-page="currentPage"
        :page-size="10"
        :total="50"
        layout="total, prev, pager, next"
        style="margin-top: 20px; justify-content: flex-end;"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentPage = ref(1)

const tableData = ref([
  { id: 1, roomCode: 'PDR-001', roomName: '1号配电间', building: 'A栋', floor: '1F', voltage: '10kV', capacity: 1000, status: '正常运行', responsible: '张工' },
  { id: 2, roomCode: 'PDR-002', roomName: '2号配电间', building: 'A栋', floor: 'B1', voltage: '10kV', capacity: 1500, status: '正常运行', responsible: '李工' },
  { id: 3, roomCode: 'PDR-003', roomName: '3号配电间', building: 'B栋', floor: '1F', voltage: '10kV', capacity: 800, status: '检修中', responsible: '王工' },
  { id: 4, roomCode: 'PDR-004', roomName: '4号配电间', building: 'B栋', floor: 'B1', voltage: '10kV', capacity: 1200, status: '正常运行', responsible: '赵工' },
  { id: 5, roomCode: 'PDR-005', roomName: '5号配电间', building: 'C栋', floor: '1F', voltage: '10kV', capacity: 2000, status: '正常运行', responsible: '钱工' }
])

const getStatusType = (status) => {
  const map = {
    '正常运行': 'success',
    '检修中': 'warning',
    '故障': 'danger',
    '停用': 'info'
  }
  return map[status] || 'info'
}

const handleAdd = () => {
  ElMessage.info('新增配电间功能')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑配电间：${row.roomName}`)
}

const handleDelete = (row) => {
  ElMessage.warning(`删除配电间：${row.roomName}`)
}
</script>

<style scoped>
.page-container {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
